

class GazerException extends Exception{ 
    
    GazerException(){    super()    }
    
    GazerException(String msg){    super(msg)    }
    
}

params = ['d13.v0':'1235', 'd13.v1':'1235',  'd115.v0':'1235', 'd115.v1':'1235', '1234':'d123.v3', 'c0':'field', 'c1':'field2']

x = [:]

if (x[1] == null)
{  x[1] = [3:1] }
else  { x[1][3] = 1}
if (x[1] == null)
{  x[1] = [2:1] }
else  { x[1][2] = 1}
println x


        def paramVs = params.findAll{ key, value -> key ==~ /^d[0-9]*[.]v[0-9]*$/ }
        def paramCs = params.findAll{ key, value -> key ==~ /^c[0-9]*$/ }

println paramVs
println paramCs

        def argVs = paramVs.inject([:]){ result, entry -> 
          
          def key = entry.getKey()
          def value = entry.getValue()
          def tmp = key.split("[.]")

          def d = Integer.parseInt(tmp[0].replace("d", ""))
          def v = Integer.parseInt(tmp[1].replace("v", ""))
         
          if (result[(d)] == null){
            result[(d)] = [ (v) : value ]
          }
          else{
            result[(d)][(v)] = value
          }
          return result
        }

        def argCs = paramCs.inject([:]){result, entry ->
           def key = entry.getKey()
           def value = entry.getValue()
           def c = Integer.parseInt(key.replace("c", ""))
           
           result[(c)] = value
           return result
        }

//         validation column indexes

        if (!(argCs.keySet().max()  + 1 == argCs.keySet().size() &&  argCs.keySet().min() == 0)){
          throw new GazerException("column indexes not in the form or [0..n]" );
        }

         
//         validate filter value indexes

        def checkValueIndexes = argVs.every{ // argCs is external var
          def keyset = it.getValue().keySet()
          println it.getValue().keySet()
          println keyset.size()
          println keyset.max()
          println keyset.min()
            println argCs.keySet().size()
          println argCs.keySet().max()
          println argCs.keySet().min()       
          keyset.size() == argCs.keySet().size() &&
              keyset.max() == argCs.keySet().max() &&
              keyset.min() == argCs.keySet().min() 
        }
        if (!checkValueIndexes){
          throw new GazerException("filter value indexes not in the form of [0..n]");
        }
        